 <?php
// 新闻公告控制器
class InformationAction extends CommonAction {
    /**
     * [newsList description]新闻模版跳转
     * @return [type] [description]
     */
	public function newsList(){
		$this->display("Information:newsList");
	}

	/**
     * [leaveListData description]获取新闻请假列表
     * @return [type] [description]
     */
    public function newsListData(){
    	$result = array();
        $info_type='新闻';
    	$result['total'] = $this->getListCount($info_type);
    	$result['rows'] = $this->getList($info_type);
    	echo json_encode($result);
    }

    /**
     * [adList description]公告模版跳转
     * @return [type] [description]
     */
    public function adList(){
        $this->display("Information:adList");
    }

    /**
     * [leaveListData description]获取广告请假列表
     * @return [type] [description]
     */
    public function adListData(){
        $result = array();
        $info_type='公告';
        $result['total'] = $this->getListCount($info_type);
        $result['rows'] = $this->getList($info_type);
        echo json_encode($result);
    }

    /**
     * 获取列表
     */
    public function getList($info_type){
    	import("ORG.Util.Page");
    	$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    	$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
        $result=array();
       	$info=M('Information');
       	$data=$info->where("info_type='".$info_type."'")->page($page,$rows)->select();
        foreach ($data as $value) {
            $value['info_employe_id']=$this->getOneEmployeName($value['info_employe_id']);
            $result[]=$value;
        }
        return $result;
    }
    
    /**
     * 获取列表数量
     */
    public function getListCount($info_type){	
    	$info=M('Information');
    	$result=$info->where("info_type='".$info_type."'")->count();
        return $result;
    }

    /**
     * [detailPage description]查看详情
     * @return [type] [description]
     */
    public function detailPage(){
        $info_id=I('info_id');
        $information=M('Information');
        $this->detailData=$information->where("info_id='".$info_id."'")->select();
        $this->display("Information:detailPage");
    }

    /**
     * [addInfo description]添加公告模版
     */
    public function addInfo(){
        $this->assign('info_type',I('info_type'));
        $this->display("Information:addInfo");
    }

    /**
     * [addInfoPost description]添加公告处理
     */
    public function addInfoPost(){
        $info=M('Information');
        $info->info_type=I('info_type');
        $info->info_title=I('info_title');
        $content=$_POST['info_content'];
        $content = str_replace('&nbsp;', '&amp;nbsp;', $content);
        $content = str_replace('&gt;', '&amp;gt;', $content);
        $content = str_replace('&lt;', '&amp;lt;', $content);
        $info->info_content=$content;
        $info->info_time=time();
        $info->info_employe_id=session('employe_id');
        if($info->add()){
            $sign=array('info_type' => I('info_type'));
            echo json_encode($sign);
        }
        else{
            echo 'no';
        }
    }

    public function editOne(){
        $info_id=I('info_id');
        $info=M('Information');
        $this->infoData=$info->where("info_id='".$info_id."'")->select();

        $this->display("Information:editInfo");
    }

    public function saveInfoPost(){
        $info=M('Information');
        $info_id=I("info_id");
        $data['info_title']=I('info_title');
        $content=$_POST['info_content'];

        $data['info_content']=$content;
        $data['info_time']=time();
        $result=$info->where("info_id='".$info_id."'")->save($data);
        $info_type=$info->where("info_id='".$info_id."'")->getField('info_type');
        if($result){
            echo $info_type;
        }
        else{
            echo 'no';
        }
    }


    /**
     * [delInfo description]删除信息
     * @return [type] [description]
     */
    public function delInfo(){
        $info_id=$_POST['info_id'];
        $info=M('Information');
        $info->where("info_id ='".$info_id."'")->delete();
        //echo 'ok';
        /*if($result){
            echo 'ok';
        }
        else{
            echo 'no';
        }*/
    }

    public function delEmploye(){
        $employe=M('Employe');
        $employe_id=$_POST['employe_id'];
        $result=$employe->where("employe_id ='".$employe_id."'")->delete();
        if($result){
            echo 'ok';
        }
        else{
            echo 'no';
        }
    }

}